<template>
  <div class="home-new" ref="target">
    <HomePanel title="新鲜好物" subTitle="新鲜出炉 品质保障">
      <template #right>
        <xtxMore path="/"/>
      </template>

      <!-- 面板内容 -->
      <transition name="fade" >
        <ul v-if="goods.length" ref="pannel" class="goods-list">
          <li v-for="items in goods" :key="items.id">
            <router-link :to="`/product/${items.id}`">
              <img :src="items.picture" alt="">
              <p class="name ellipsis">{{ items.name }}</p>
              <p class="price">&yen;{{ items.price }}</p>
            </router-link>
          </li>
        </ul>

        <!-- 缓冲白屏骨架 -->
        <HomeSkeleton v-else bg="#f0f9f4"/>
      </transition>
    </HomePanel>
  </div>
</template>

<script>
import HomePanel from './home-panel.vue'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hooks'
import { findNew } from '@/api/home'
// import { ref } from 'vue'
export default {
  name: 'HomeNew',
  components: {
    HomePanel,
    HomeSkeleton
  },
  setup () {
    // const goods = ref([])

    // findNew().then(data => {
    //   goods.value = data.result
    //   console.log(data.result)
    // })

    const { target, result } = useLazyData(findNew)
    // goods.value = result
    return { goods: result, target }
  }
}
</script>

<style lang="less" scoped>
 .goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    .hoverShadow(); // 上浮动画
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .price {
      color: @priceColor;
    }
  }
 }
</style>
